package org.brownflat.lighthouse.monitoring.ci;

import org.joda.time.DateTime;

import java.io.Serializable;

public class Build implements Serializable {
    private String project = null;
    private boolean broken = false;
    private DateTime date = null;
    private String name = null;
    private String buildNumber = null;
    private String rawData = null;

    public String getProject() {
        return project;
    }

    public void setProject(String project) {
        this.project = project;
    }

    public String getRawData() {
        return rawData;
    }

    public void setRawData(String rawData) {
        this.rawData = rawData;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setBroken(boolean broken) {
        this.broken = broken;
    }

    public boolean isBroken() {
        return broken;
    }

    public DateTime getDate() {
        return date;
    }

    public void setDate(DateTime date) {
        this.date = date;
    }

    public String getBuildSeriesKey() {
        return String.format("%s-%s", getProject(), getName()).toLowerCase().replace(" ", "");
    }

    public String getBuildKey() {
        return String.format("%s-%s-%s", getProject(), getName(), getBuildNumber()).toLowerCase().replace(" ", "");
    }

    public String toString() {
        return String.format("BUILD [Project:%s][Build:%s][Build No:%s][Date: %s][Broken?:%s]", getProject(), getName(), getBuildNumber(), getDate(), isBroken());
    }

    public void setBuildNumber(String buildNumber) {
        this.buildNumber = buildNumber;
    }

    public String getBuildNumber() {
        return buildNumber;
    }

    public boolean matchesPattern(String thisName) {
        boolean match = false;
        if(project != null) {
            match = project.matches(thisName);
        }

        if(!match && name != null) {
            match = name.matches(thisName);
        }
        return match;
    }
}
